package main

import (
	v1 "xjxtld/api/v1"
	v2 "xjxtld/api/v2"

	// v2 "xjxtld/api/v2"

	_ "xjxtld/internal/packed"

	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
	_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gfile"
)

func MiddlewareCORS(r *ghttp.Request) {
	r.Response.CORSDefault()
	r.Middleware.Next()
}

//var heart *string

func init() {
	//v1.BusAndOrg()
	v1.Gfstart()     //初始化，获取JT809上级平台端口和IP号等信息
	v1.UpDateTable() //更新组织信息
	go v1.UpDatePB() //更新排班
	//go v1.Jt809()          //发起809客户端
	go v2.RunJT809()       //发起809客户端
	go v1.Repose()         //接收并处理数据
	go v1.Supplement()     //补包
	go v1.PlanArriveTime() //更新末班到站时间
	go v1.UpdateSanitize() //每5分钟更新当天排班数据到fa_sanitize表
}

func main() {
	s := g.Server()
	s.EnablePProf()
	s.SetIndexFolder(true)
	s.SetServerRoot("./")
	//s.AddSearchPath("./tmp")
	s.Group("/api.v1", func(group *ghttp.RouterGroup) {
		group.Middleware(MiddlewareCORS)
		group.ALL("/TimeGet", v1.TimeGet)
		group.ALL("/Xjjllist", v1.List)
		//group.ALL("/UpDateXjxt", v1.UpDateXjxt)

	})
	s.SetServerRoot(gfile.MainPkgPath())
	//s.SetPort(18520)
	s.SetPort(18829)
	s.Run()
}

// 设置全局上下文
